﻿
using FastReport.Export.Pdf;
using FastReport.Export.OoXML;
using FastReport.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace HookupAppForm
{
    public class FastReportHelper
    {
        //static LoginUserInfo loginUserInfo = Cache.Instance["LoginUserInfo"] as LoginUserInfo;
        #region 报表设计方法
        ////参数dt_Data/当前模块数据源；dt_DataName/当前模块数据源名称；ReportCode/报表编码；dt_Data1/预留数据源；dt_Data1Name/预留数据源名称
        public static void ReportDesign(DataTable dt_Data, string dt_DataName, string ReportCode, DataTable dt_Data1 = null, string dt_Data1Name = null,
            DataTable dt_Data2 = null, string dt_Data2Name = null, DataTable dt_Data3 = null, string dt_Data3Name = null, DataTable dt_Data4 = null, string dt_Data4Name = null,
            DataTable dt_Data5 = null, string dt_Data5Name = null, DataTable dt_Data6 = null, string dt_Data6Name = null, DataTable dt_Data7 = null, string dt_Data7Name = null,
            DataTable dt_Data8 = null, string dt_Data8Name = null, DataTable dt_Data9 = null, string dt_Data9Name = null, DataTable dt_Data10 = null, string dt_Data10Name = null,
            DataTable dt_Data11 = null, string dt_Data11Name = null, DataTable dt_Data12 = null, string dt_Data12Name = null, DataTable dt_Data13 = null, string dt_Data13Name = null,
            DataTable dt_Data14 = null, string dt_Data14Name = null, DataTable dt_Data15 = null, string dt_Data15Name = null, DataTable dt_Data16 = null, string dt_Data16Name = null,
            DataTable dt_Data17 = null, string dt_Data17Name = null, DataTable dt_Data18 = null, string dt_Data18Name = null, DataTable dt_Data19 = null, string dt_Data19Name = null,
            DataTable dt_Data20 = null, string dt_Data20Name = null, DataTable dt_Data21 = null, string dt_Data21Name = null, DataTable dt_Data22 = null, string dt_Data22Name = null,
            DataTable dt_Data23 = null, string dt_Data23Name = null, DataTable dt_Data24 = null, string dt_Data24Name = null, DataTable dt_Data25 = null, string dt_Data25Name = null,
            DataTable dt_ReleaseIrr = null, string dt_Data26Name = null, DataTable dt_Data27 = null, string dt_Data27Name = null, DataTable dt_Data28 = null, string dt_Data28Name = null)
        {
            //查询报表编码查询报表数据；封装方法参数为Code/报表编码
            DataTable dt_page = new DataTable(); ;// BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");
            if (dt_page.Rows.Count <= 0)
            {
                ////创建预约单对应的报表新数据
                //ReportPageInfo pageinfo = new ReportPageInfo();
                //pageinfo.Code = ReportCode; //封装方法参数为Code / 报表编码
                //pageinfo.VersionNumber = 1;//版本默认1
                //pageinfo.SyncTag = true;//同步状态默认true，需要同步
                //pageinfo.Creator = loginUserInfo.FullName;
                //pageinfo.CreateTime = DateTime.Now;
                ////查找未分组报表类型(没有则创建)
                //ReportTypeInfo typeinfo = new ReportTypeInfo();
                //DataTable dt_Type = BLLFactory<ReportType>.Instance.SqlTable("select * from TB_RPT_Type where Name='未分组'");
                //if (dt_Type.Rows.Count <= 0)
                //{
                //    typeinfo.Code = "WFZ";
                //    typeinfo.Name = "未分组";
                //    typeinfo.Creator = loginUserInfo.FullName;
                //    typeinfo.CreateTime = DateTime.Now;
                //    BLLFactory<ReportType>.Instance.Insert(typeinfo);
                //}
                //DataTable dt_Type1 = BLLFactory<ReportType>.Instance.SqlTable("select * from TB_RPT_Type where Name='未分组' and Code = 'WFZ' ");
                //if (dt_Type1.Rows.Count > 0)
                //{
                //    pageinfo.TypeID = Convert.ToInt32(dt_Type1.Rows[0]["ID"]);
                //    BLLFactory<ReportPage>.Instance.Insert(pageinfo);
                //}
            }
            #region 报表设计功能前置逻辑
            //查询报表编码查询报表数据；封装方法参数为Code/报表编码
            DataTable TB_RPT_Page = new DataTable(); ;//BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
            int PageID = 1;// Convert.ToInt32(TB_RPT_Page.Rows[0]["ID"]);
            string Code = "KSH";//Convert.ToString(TB_RPT_Page.Rows[0]["Code"]);//编码
            string VersionNumber = "送签"; //uConvert.ToString(TB_RPT_Page.Rows[0]["VersionNumber"]);//版本
            if (string.IsNullOrEmpty(VersionNumber) || VersionNumber.Equals("0"))
            {
                VersionNumber = "1";
            }
            Byte[] FileStream = null;// (Byte[])(TB_RPT_Page.Rows[0]["FileStream"]);
            string ReportName = Code + "_" + VersionNumber;
            bool SyncTag = false;//Convert.ToBoolean(TB_RPT_Page.Rows[0]["SyncTag"]);//同步状态

            if (SyncTag)//需要同步
            {
                //校验是否需要创建文件夹
                if (!System.IO.Directory.Exists(@".//FastReports"))
                {
                    System.IO.Directory.CreateDirectory(@".//FastReports");
                }
                //判断选中数据FileStream报表二进制值是否为空(为空就调用本地空白标准模板并转换为二进制值)
                if (FileStream.Length <= 0)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //创建或打开指定文件并传入二进制值
                using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsOpen.Write(FileStream, 0, FileStream.Length);
                    fsOpen.Close();
                }
            }
            else//不需要同步
            {
                //获取标准模板
                if (FileStream ==null)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //查询报表编码查询报表数据；封装方法参数为Code/报表编码
                DataTable dtVersionNumber = null;// BLLFactory<ReportPageSVN>.Instance.SqlTable(@" select Code,VersionNumber from TB_RPT_Page_SVN where Code='" + ReportCode + @"'
                                 //union
                                 //select Code, VersionNumber from TB_RPT_Page where Code = '" + ReportCode + "' ");
                string fileReportName = "";
                if (dtVersionNumber!=null)
                {
                    for (int i = dtVersionNumber.Rows.Count - 1; i >= 0; i--)
                    {
                        string code = Convert.ToString(dtVersionNumber.Rows[i]["Code"]);
                        string number = Convert.ToString(dtVersionNumber.Rows[i]["VersionNumber"]);
                        string Name = code + "_" + number;
                        if (File.Exists(@".//FastReports\" + Name + ".frx"))//文件已存在
                        {
                            //查询到指定数据，跳出循环
                            fileReportName = Name;
                            break;
                        }
                    }
                    //如果本地无对应文件则调用数据库二进制字段
                    if (string.IsNullOrEmpty(fileReportName))
                    {
                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                    else//如果本地有对应文件则把对应文件名赋值给报表文件名字段(此处赋值是因为后续打开报表设计页面固定调用ReportName变量。)
                    {
                        ReportName = fileReportName;
                    }
                }
            }
            #endregion

            #region 打开设计页面之前获取原始报表文件二进制数据，用于后续对比
            //FileStream fsSave1 = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.Open);
            //BinaryReader br1 = new BinaryReader(fsSave1);
            //Byte[] OldFileStream = br1.ReadBytes((int)fsSave1.Length);//原始报表二进制数据，用于创建本地新文件
            //fsSave1.Close();
            #endregion 

            #region 打开设计页面编辑并保存
            //打开报表设计页面(方法需要预先手动创建对应FastReport空报表文件)
            using (FastReport.Report report = new FastReport.Report())
            {
                report.Load(@".//FastReports\" + ReportName + ".frx");
                //加载数据源
                report.RegisterData(dt_Data, dt_DataName);

                #region 预留数据集位置
                if (dt_Data1 != null)
                {
                    report.RegisterData(dt_Data1, dt_Data1Name);
                }
                if (dt_Data2 != null)
                {
                    report.RegisterData(dt_Data2, dt_Data2Name);
                }
                if (dt_Data3 != null)
                {
                    report.RegisterData(dt_Data3, dt_Data3Name);
                }
                if (dt_Data4 != null)
                {
                    report.RegisterData(dt_Data4, dt_Data4Name);
                }
                if (dt_Data5 != null)
                {
                    report.RegisterData(dt_Data5, dt_Data5Name);
                }
                if (dt_Data6 != null)
                {
                    report.RegisterData(dt_Data6, dt_Data6Name);
                }
                if (dt_Data7 != null)
                {
                    report.RegisterData(dt_Data7, dt_Data7Name);
                }
                if (dt_Data8 != null)
                {
                    report.RegisterData(dt_Data8, dt_Data8Name);
                }
                if (dt_Data9 != null)
                {
                    report.RegisterData(dt_Data9, dt_Data9Name);
                }
                if (dt_Data10 != null)
                {
                    report.RegisterData(dt_Data10, dt_Data10Name);
                }
                if (dt_Data11 != null)
                {
                    report.RegisterData(dt_Data11, dt_Data11Name);
                }
                if (dt_Data12 != null)
                {
                    report.RegisterData(dt_Data12, dt_Data12Name);
                }
                if (dt_Data13 != null)
                {
                    report.RegisterData(dt_Data13, dt_Data13Name);
                }
                if (dt_Data14 != null)
                {
                    report.RegisterData(dt_Data14, dt_Data14Name);
                }
                if (dt_Data15 != null)
                {
                    report.RegisterData(dt_Data15, dt_Data15Name);
                }
                if (dt_Data16 != null)
                {
                    report.RegisterData(dt_Data16, dt_Data16Name);
                }
                if (dt_Data17 != null)
                {
                    report.RegisterData(dt_Data17, dt_Data17Name);
                }
                if (dt_Data18 != null)
                {
                    report.RegisterData(dt_Data18, dt_Data18Name);
                }
                if (dt_Data19 != null)
                {
                    report.RegisterData(dt_Data19, dt_Data19Name);
                }
                if (dt_Data20 != null)
                {
                    report.RegisterData(dt_Data20, dt_Data20Name);
                }
                if (dt_Data21 != null)
                {
                    report.RegisterData(dt_Data21, dt_Data21Name);
                }
                if (dt_Data22 != null)
                {
                    report.RegisterData(dt_Data22, dt_Data22Name);
                }
                if (dt_Data23 != null)
                {
                    report.RegisterData(dt_Data23, dt_Data23Name);
                }
                if (dt_Data24 != null)
                {
                    report.RegisterData(dt_Data24, dt_Data24Name);
                }
                if (dt_Data25 != null)
                {
                    report.RegisterData(dt_Data25, dt_Data25Name);
                }
                if (dt_ReleaseIrr != null)
                {
                    report.RegisterData(dt_ReleaseIrr, dt_Data26Name);
                }
                if (dt_Data27 != null)
                {
                    report.RegisterData(dt_Data27, dt_Data27Name);
                }
                if (dt_Data28 != null)
                {
                    report.RegisterData(dt_Data28, dt_Data28Name);
                }
                #endregion
                report.Design();
                //报表设计操作完毕、报表文件转换为二进制数据
                FileStream fsSave = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.Open);
                BinaryReader br = new BinaryReader(fsSave);
                FileStream = br.ReadBytes((int)fsSave.Length);
                Byte[] NewFileStream = FileStream;//最新报表二进制数据，用于创建本地新文件
                br.Close();
                fsSave.Close();
                //ReportPageInfo info = BLLFactory<ReportPage>.Instance.FindByID(PageID);

                #region 根据报表数据是否相同判断需不需要版本控制
                //创建一个哈希算法对象 

                //using (HashAlgorithm hash = HashAlgorithm.Create())
#pragma warning restore SYSLIB0007 // 类型或成员已过时
                //{
                //byte[] hashByte1 = hash.ComputeHash(NewFileStream);//哈希算法根据文本得到哈希码的字节数组 
                //byte[] hashByte2 = hashByte1;//;hash.ComputeHash(OldFileStream);
                //string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串 
                //string str2 = BitConverter.ToString(hashByte2);
                //if (!str1.Equals(str2))
                //{
                //保存原本数据到SVN版本备份表
                //ReportPageSVNInfo SVNInfo = new ReportPageSVNInfo
                //{
                //    TypeID = info.TypeID,
                //    Code = info.Code,
                //    Name = info.Name,
                //    FileStream = info.FileStream,
                //    VersionNumber = info.VersionNumber,
                //    Creator = loginUserInfo.FullName,
                //    CreateTime = DateTime.Now
                //};
                //BLLFactory<ReportPageSVN>.Instance.Insert(SVNInfo);
                ////更新正式表版本号并保存
                //info.Modifier = loginUserInfo.FullName;
                //info.ModiTime = DateTime.Now;
                //info.ModifyNum = info.ModifyNum + 1;
                //info.FileStream = FileStream;
                //info.VersionNumber = info.VersionNumber + 1;
                //try
                //{
                //    BLLFactory<ReportPage>.Instance.Update(info, info.ID);
                //    FileStream = info.FileStream;
                //}
                //catch (Exception ex)
                //{
                //    LogTextHelper.Error(ex);
                //    MessageDxUtil.ShowError(ex.Message);
                //}
                //}
                //}
                #endregion

                #region 修改本地文件名
                //创建或打开指定文件并传入二进制值
                using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsOpen.Write(FileStream, 0, FileStream.Length);
                    fsOpen.Close();
                }
                //if (!SyncTag)//不需要同步
                //{
                //    //创建一个哈希算法对象 
                //    using (HashAlgorithm hash = HashAlgorithm.Create())
                //    {
                //        byte[] hashByte1 = hash.ComputeHash(NewFileStream);//哈希算法根据文本得到哈希码的字节数组 
                //        byte[] hashByte2 = hashByte1;//hash.ComputeHash(OldFileStream);
                //        string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串 
                //        string str2 = BitConverter.ToString(hashByte2);
                //        if (!str1.Equals(str2))
                //        {
                //            DataTable Page = null;// BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
                //            string NewCode = Convert.ToString(Page.Rows[0]["Code"]);//编码
                //            string NewVersionNumber = Convert.ToString(Page.Rows[0]["VersionNumber"]);//版本
                //            if (string.IsNullOrEmpty(NewVersionNumber) || NewVersionNumber.Equals("0"))
                //            {
                //                NewVersionNumber = "1";
                //            }
                //            string NewReportName = NewCode + "_" + NewVersionNumber;

                //            //创建或打开指定文件并传入二进制值
                //            using (FileStream fsOpen = new FileStream(@".//FastReports\" + NewReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                //            {
                //                fsOpen.Write(FileStream, 0, FileStream.Length);
                //                fsOpen.Close();
                //            }
                //        }
                //    }
                //}
            }
            #endregion

            #endregion
        }
        #endregion

        #region 报表预览和打印
        //参数dt_Data/当前模块数据源；dt_DataName/当前模块数据源名称；ReportCode/报表编码；ReportStatus/报表状态(打印还是预览)；dt_Data1/预留数据源；dt_Data1Name/预留数据源名称
        //string TotalAddress = null
        public static PrintReturn ReportShowOrPrint(DataTable dt_Data, string dt_DataName, string ReportCode, string ReportStatus, string PrinterName = null,
            DataTable dt_Data1 = null, string dt_Data1Name = null, DataTable dt_Data2 = null, string dt_Data2Name = null,
            DataTable dt_Data3 = null, string dt_Data3Name = null, DataTable dt_Data4 = null, string dt_Data4Name = null,
            DataTable dt_Data5 = null, string dt_Data5Name = null, DataTable dt_Data6 = null, string dt_Data6Name = null,
            DataTable dt_Data7 = null, string dt_Data7Name = null, DataTable dt_Data8 = null, string dt_Data8Name = null,
            DataTable dt_Data9 = null, string dt_Data9Name = null, DataTable dt_Data10 = null, string dt_Data10Name = null,
            DataTable dt_Data11 = null, string dt_Data11Name = null, DataTable dt_Data12 = null, string dt_Data12Name = null,
            DataTable dt_Data13 = null, string dt_Data13Name = null, DataTable dt_Data14 = null, string dt_Data14Name = null,
            DataTable dt_Data15 = null, string dt_Data15Name = null, DataTable dt_Data16 = null, string dt_Data16Name = null,
            DataTable dt_Data17 = null, string dt_Data17Name = null, DataTable dt_Data18 = null, string dt_Data18Name = null,
            DataTable dt_Data19 = null, string dt_Data19Name = null, DataTable dt_Data20 = null, string dt_Data20Name = null,
            DataTable dt_Data21 = null, string dt_Data21Name = null, DataTable dt_Data22 = null, string dt_Data22Name = null,
            DataTable dt_Data23 = null, string dt_Data23Name = null, DataTable dt_Data24 = null, string dt_Data24Name = null,
            DataTable dt_Data25 = null, string dt_Data25Name = null, DataTable dt_ReleaseIrr = null, string v = null,
            DataTable dt_Data27 = null, string dt_Data27Name = null, DataTable dt_Data28 = null, string dt_Data28Name = null)
        {

            PrintReturn printReturn = new PrintReturn();
            DataTable dt = new DataTable();//BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
            if (dt.Rows.Count > 0)
            {
                #region 报表预览
                int PageID = 1;// Convert.ToInt32(TB_RPT_Page.Rows[0]["ID"]);
                string Code = "KSH";//Convert.ToString(TB_RPT_Page.Rows[0]["Code"]);//编码
                string VersionNumber = "送签"; //uConvert.ToString(TB_RPT_Page.Rows[0]["VersionNumber"]);//版本
                if (string.IsNullOrEmpty(VersionNumber) || VersionNumber.Equals("0"))
                {
                    VersionNumber = "1";
                }
                Byte[] FileStream = null; //(Byte[])(dt.Rows[0]["FileStream"]);
                string ReportName = Code + "_" + VersionNumber;
                bool SyncTag = Convert.ToBoolean(dt.Rows[0]["SyncTag"]);//同步状态

                if (SyncTag)//需要同步
                {
                    if (!File.Exists(@".//FastReports\" + ReportName + ".frx"))//本地不存在文件，再创建 by shx 210709
                    {
                        if (FileStream.Length <= 0)
                        {
                            printReturn.Status = 0;
                            printReturn.PrintName = "";
                            return printReturn;

                        }
                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                }
                else//不需要同步
                {
                    if (FileStream ==null)
                    {
                        printReturn.Status = 0;
                        printReturn.PrintName = "";
                        return printReturn;

                    }
                    //DataTable dtVersionNumber = BLLFactory<ReportPageSVN>.Instance.SqlTable(@" select Code,VersionNumber from TB_RPT_Page_SVN where Code='" + ReportCode + @"'
                    //                                                                        union
                    //                                                                        select Code, VersionNumber from TB_RPT_Page where Code = '" + ReportCode + "' ");//注释 by shx 210709
                    string fileReportName = "";//为了寻找本地是否存在报表
                                               //if (dtVersionNumber.Rows.Count > 0)
                                               //{
                                               //for (int i = dtVersionNumber.Rows.Count - 1; i >= 0; i--)
                    for (int i = Convert.ToInt32(VersionNumber); i >= 0; i--)//by shx 210709
                    {
                        string number = i.ToString();//by shx 210709 Convert.ToString(dtVersionNumber.Rows[i]["VersionNumber"]);
                        string Name = ReportCode + "_" + number;
                        if (File.Exists(@".//FastReports\" + Name + ".frx"))//文件存在
                        {
                            //查询到指定数据，跳出循环
                            fileReportName = Name;
                            break;
                        }
                    }
                    //如果本地无对应文件则调用数据库二进制字段
                    if (string.IsNullOrEmpty(fileReportName))
                    {
                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                    else//如果本地有对应文件则把对应文件名赋值给报表文件名字段(此处赋值是因为后续打开报表设计页面固定调用ReportName变量。)
                    {
                        ReportName = fileReportName;
                    }
                    //}
                }
                //DataTable TB_RPT_Page = BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
                //打开报表预览页面(方法需要预先手动创建对应FastReport空报表文件)
                using (FastReport.Report report = new FastReport.Report())
                {
                    report.Load(@".//FastReports\" + ReportName + ".frx");
                    //加载数据源
                    report.RegisterData(dt_Data, dt_DataName);
                    //report.RegisterData(TB_RPT_Page, "TB_RPT_Page");

                    #region 预留数据集位置
                    if (dt_Data1 != null)
                    {
                        report.RegisterData(dt_Data1, dt_Data1Name);
                    }
                    if (dt_Data2 != null)
                    {
                        report.RegisterData(dt_Data2, dt_Data2Name);
                    }
                    if (dt_Data3 != null)
                    {
                        report.RegisterData(dt_Data3, dt_Data3Name);
                    }
                    if (dt_Data4 != null)
                    {
                        report.RegisterData(dt_Data4, dt_Data4Name);
                    }
                    if (dt_Data5 != null)
                    {
                        report.RegisterData(dt_Data5, dt_Data5Name);
                    }
                    if (dt_Data6 != null)
                    {
                        report.RegisterData(dt_Data6, dt_Data6Name);
                    }
                    if (dt_Data7 != null)
                    {
                        report.RegisterData(dt_Data7, dt_Data7Name);
                    }
                    if (dt_Data8 != null)
                    {
                        report.RegisterData(dt_Data8, dt_Data8Name);
                    }
                    if (dt_Data9 != null)
                    {
                        report.RegisterData(dt_Data9, dt_Data9Name);
                    }
                    if (dt_Data10 != null)
                    {
                        report.RegisterData(dt_Data10, dt_Data10Name);
                    }
                    if (dt_Data11 != null)
                    {
                        report.RegisterData(dt_Data11, dt_Data11Name);
                    }
                    if (dt_Data12 != null)
                    {
                        report.RegisterData(dt_Data12, dt_Data12Name);
                    }
                    if (dt_Data13 != null)
                    {
                        report.RegisterData(dt_Data13, dt_Data13Name);
                    }
                    if (dt_Data14 != null)
                    {
                        report.RegisterData(dt_Data14, dt_Data14Name);
                    }
                    if (dt_Data15 != null)
                    {
                        report.RegisterData(dt_Data15, dt_Data15Name);
                    }
                    if (dt_Data16 != null)
                    {
                        report.RegisterData(dt_Data16, dt_Data16Name);
                    }
                    if (dt_Data17 != null)
                    {
                        report.RegisterData(dt_Data17, dt_Data17Name);
                    }
                    if (dt_Data18 != null)
                    {
                        report.RegisterData(dt_Data18, dt_Data18Name);
                    }
                    if (dt_Data19 != null)
                    {
                        report.RegisterData(dt_Data19, dt_Data19Name);
                    }
                    if (dt_Data20 != null)
                    {
                        report.RegisterData(dt_Data20, dt_Data20Name);
                    }
                    if (dt_Data21 != null)
                    {
                        report.RegisterData(dt_Data21, dt_Data21Name);
                    }
                    if (dt_Data22 != null)
                    {
                        report.RegisterData(dt_Data22, dt_Data22Name);
                    }
                    if (dt_Data23 != null)
                    {
                        report.RegisterData(dt_Data23, dt_Data23Name);
                    }
                    if (dt_Data24 != null)
                    {
                        report.RegisterData(dt_Data24, dt_Data24Name);
                    }
                    if (dt_Data25 != null)
                    {
                        report.RegisterData(dt_Data25, dt_Data25Name);
                    }
                    if (dt_ReleaseIrr != null)
                    {
                        report.RegisterData(dt_ReleaseIrr, v);
                    }
                    if (dt_Data27 != null)
                    {
                        report.RegisterData(dt_Data27, dt_Data27Name);
                    }
                    if (dt_Data28 != null)
                    {
                        report.RegisterData(dt_Data28, dt_Data28Name);
                    }
                    #endregion
                    //PDF打印配置
                    if (PrinterName.Equals("Microsoft Print to PDF"))
                    {
                        if (dt_Data2 != null)
                        {
                            if (dt_Data1 != null && dt_Data1.Rows.Count != 0)
                            {
                                string N = "";
                                for (int i = 0; i < dt_Data1.Rows.Count; i++)
                                {
                                    N += dt_Data1.Rows[i][0];
                                }
                                report.PrintSettings.PrintToFile = true;
                                //report.PrintSettings.PrintToFileName = TotalAddress;
                                report.PrintSettings.PrintToFileName = N;//路径
                            }
                        }
                    }
                    if (ReportStatus.Equals("打印"))
                    {
                        if (!string.IsNullOrEmpty(PrinterName))
                        {
                            report.PrintSettings.ShowDialog = false;
                        }
                        else
                        {
                            report.PrintSettings.ShowDialog = true;
                        }
                        FastReport.EnvironmentSettings settings = new FastReport.EnvironmentSettings();
                        settings.ReportSettings.ShowProgress = false;
                        report.PrintSettings.Printer = PrinterName;

                        report.Print();//报表打印
                    }
                    if (ReportStatus.Equals("预览"))
                    {
                        if (!string.IsNullOrEmpty(PrinterName))
                        {
                            report.PrintSettings.ShowDialog = false;
                        }
                        else
                        {
                            report.PrintSettings.ShowDialog = true;
                        }
                        report.PrintSettings.Printer = PrinterName;
                        report.Show();//报表预览
                    }

                    printReturn.Status = 1;
                    printReturn.PrintName = report.PrintSettings.Printer;//获取打印机名称report.PrintSettings.Printer
                    return printReturn;

                }
                #endregion
            }
            else
            {
                printReturn.Status = 0;
                printReturn.PrintName = "";
                return printReturn;//未找到报表
            }
        }
        #endregion

        #region 报表导出
        //参数dt_Data/当前模块数据源；dt_DataName/当前模块数据源名称；ReportCode/报表编码；ReportStatus/报表状态(打印还是预览)；dt_Data1/预留数据源；dt_Data1Name/预留数据源名称
        //string TotalAddress = null
        public static PrintReturn ReportExport(DataTable dt_Data, string dt_DataName, string ReportCode, string ReportStatus, string PrinterName = null, DataTable dt_Data1 = null, string dt_Data1Name = null,
            DataTable dt_Data2 = null, string dt_Data2Name = null, DataTable dt_Data3 = null, string dt_Data3Name = null, DataTable dt_Data4 = null, string dt_Data4Name = null,
            DataTable dt_Data5 = null, string dt_Data5Name = null, DataTable dt_Data6 = null, string dt_Data6Name = null, DataTable dt_Data7 = null, string dt_Data7Name = null,
            DataTable dt_Data8 = null, string dt_Data8Name = null, DataTable dt_Data9 = null, string dt_Data9Name = null, DataTable dt_Data10 = null, string dt_Data10Name = null,
            DataTable dt_Data11 = null, string dt_Data11Name = null, DataTable dt_Data12 = null, string dt_Data12Name = null, DataTable dt_Data13 = null, string dt_Data13Name = null,
            DataTable dt_Data14 = null, string dt_Data14Name = null, DataTable dt_Data15 = null, string dt_Data15Name = null, DataTable dt_Data16 = null, string dt_Data16Name = null,
            DataTable dt_Data17 = null, string dt_Data17Name = null, DataTable dt_Data18 = null, string dt_Data18Name = null, DataTable dt_Data19 = null, string dt_Data19Name = null,
            DataTable dt_Data20 = null, string dt_Data20Name = null, DataTable dt_Data21 = null, string dt_Data21Name = null, DataTable dt_Data22 = null, string dt_Data22Name = null,
            DataTable dt_Data23 = null, string dt_Data23Name = null, DataTable dt_Data24 = null, string dt_Data24Name = null, DataTable dt_Data25 = null, string dt_Data25Name = null,
            DataTable dt_Data26 = null, string dt_Data26Name = null, DataTable dt_ReleaseIrr = null, string v = null, DataTable dt_Data27 = null, string dt_Data27Name = null,
            DataTable dt_Data28 = null, string dt_Data28Name = null)
        {

            PrintReturn printReturn = new PrintReturn();
            DataTable dt = new DataTable();//BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
            //查询报表，判断是否有报表存在
            if (dt.Rows.Count <= 0 || dt==null)
            {
                #region 报表导出
                int PageID = 1;// Convert.ToInt32(TB_RPT_Page.Rows[0]["ID"]);
                string Code = "KSH";//Convert.ToString(TB_RPT_Page.Rows[0]["Code"]);//编码
                string VersionNumber = "送签"; //uConvert.ToString(TB_RPT_Page.Rows[0]["VersionNumber"]);//版本
                if (string.IsNullOrEmpty(VersionNumber) || VersionNumber.Equals("0"))
                {
                    VersionNumber = "1";
                }
                Byte[] FileStream = null; //(Byte[])(dt.Rows[0]["FileStream"]);
                string ReportName = Code + "_" + VersionNumber;
                bool SyncTag = false;//Convert.ToBoolean(dt.Rows[0]["SyncTag"]);//同步状态

                if (SyncTag)//需要同步
                {
                    if (FileStream ==null )
                    {
                        printReturn.Status = 0;
                        printReturn.PrintName = "";
                        return printReturn;

                    }
                    //创建或打开指定文件并传入二进制值
                    using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        fsOpen.Write(FileStream, 0, FileStream.Length);
                        fsOpen.Close();
                    }
                }
                else//不需要同步
                {
                    if (FileStream != null)
                    {
                        printReturn.Status = 0;
                        printReturn.PrintName = "";
                        return printReturn;

                    }
                    DataTable dtVersionNumber =new DataTable() ;// BLLFactory<ReportPageSVN>.Instance.SqlTable(@" select Code,VersionNumber from TB_RPT_Page_SVN where Code='" + ReportCode + @"'
                       // union
                        //select Code, VersionNumber from TB_RPT_Page where Code = '" + ReportCode + "' ");
                    string fileReportName = "";
                    if (dtVersionNumber.Rows.Count>0)
                    {
                        for (int i = dtVersionNumber.Rows.Count - 1; i >= 0; i--)
                        {
                            string code = Convert.ToString(dtVersionNumber.Rows[i]["Code"]);
                            string number = Convert.ToString(dtVersionNumber.Rows[i]["VersionNumber"]);
                            string Name = code + "_" + number;
                            if (File.Exists(@".//FastReports\" + Name + ".frx"))//文件存在
                            {
                                //查询到指定数据，跳出循环
                                fileReportName = Name;
                                break;
                            }
                        }
                        //如果本地无对应文件则调用数据库二进制字段
                        if (string.IsNullOrEmpty(fileReportName))
                        {
                            //创建或打开指定文件并传入二进制值
                            using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                            {
                                fsOpen.Write(FileStream, 0, FileStream.Length);
                                fsOpen.Close();
                            }
                        }
                        else//如果本地有对应文件则把对应文件名赋值给报表文件名字段(此处赋值是因为后续打开报表设计页面固定调用ReportName变量。)
                        {
                            ReportName = fileReportName;
                        }
                    }
                }
                //DataTable TB_RPT_Page = BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
                //打开报表预览页面(方法需要预先手动创建对应FastReport空报表文件)
                using (FastReport.Report report = new FastReport.Report())
                {
                    report.Load(@".//FastReports\" + ReportName + ".frx");
                    //加载数据源
                    report.RegisterData(dt_Data, dt_DataName);

                    #region 预留数据集位置
                    if (dt_Data1 != null)
                    {
                        report.RegisterData(dt_Data1, dt_Data1Name);
                    }
                    if (dt_Data2 != null)
                    {
                        report.RegisterData(dt_Data2, dt_Data2Name);
                    }
                    if (dt_Data3 != null)
                    {
                        report.RegisterData(dt_Data3, dt_Data3Name);
                    }
                    if (dt_Data4 != null)
                    {
                        report.RegisterData(dt_Data4, dt_Data4Name);
                    }
                    if (dt_Data5 != null)
                    {
                        report.RegisterData(dt_Data5, dt_Data5Name);
                    }
                    if (dt_Data6 != null)
                    {
                        report.RegisterData(dt_Data6, dt_Data6Name);
                    }
                    if (dt_Data7 != null)
                    {
                        report.RegisterData(dt_Data7, dt_Data7Name);
                    }
                    if (dt_Data8 != null)
                    {
                        report.RegisterData(dt_Data8, dt_Data8Name);
                    }
                    if (dt_Data9 != null)
                    {
                        report.RegisterData(dt_Data9, dt_Data9Name);
                    }
                    if (dt_Data10 != null)
                    {
                        report.RegisterData(dt_Data10, dt_Data10Name);
                    }
                    if (dt_Data11 != null)
                    {
                        report.RegisterData(dt_Data11, dt_Data11Name);
                    }
                    if (dt_Data12 != null)
                    {
                        report.RegisterData(dt_Data12, dt_Data12Name);
                    }
                    if (dt_Data13 != null)
                    {
                        report.RegisterData(dt_Data13, dt_Data13Name);
                    }
                    if (dt_Data14 != null)
                    {
                        report.RegisterData(dt_Data14, dt_Data14Name);
                    }
                    if (dt_Data15 != null)
                    {
                        report.RegisterData(dt_Data15, dt_Data15Name);
                    }
                    if (dt_Data16 != null)
                    {
                        report.RegisterData(dt_Data16, dt_Data16Name);
                    }
                    if (dt_Data17 != null)
                    {
                        report.RegisterData(dt_Data17, dt_Data17Name);
                    }
                    if (dt_Data18 != null)
                    {
                        report.RegisterData(dt_Data18, dt_Data18Name);
                    }
                    if (dt_Data19 != null)
                    {
                        report.RegisterData(dt_Data19, dt_Data19Name);
                    }
                    if (dt_Data20 != null)
                    {
                        report.RegisterData(dt_Data20, dt_Data20Name);
                    }
                    if (dt_Data21 != null)
                    {
                        report.RegisterData(dt_Data21, dt_Data21Name);
                    }
                    if (dt_Data22 != null)
                    {
                        report.RegisterData(dt_Data22, dt_Data22Name);
                    }
                    if (dt_Data23 != null)
                    {
                        report.RegisterData(dt_Data23, dt_Data23Name);
                    }
                    if (dt_Data24 != null)
                    {
                        report.RegisterData(dt_Data24, dt_Data24Name);
                    }
                    if (dt_Data25 != null)
                    {
                        report.RegisterData(dt_Data25, dt_Data25Name);
                    }
                    if (dt_Data26 != null)
                    {
                        report.RegisterData(dt_Data26, dt_Data26Name);
                    }
                    if (dt_ReleaseIrr != null)
                    {
                        report.RegisterData(dt_ReleaseIrr, v);
                    }
                    if (dt_Data27 != null)
                    {
                        report.RegisterData(dt_Data27, dt_Data27Name);
                    }
                    if (dt_Data28 != null)
                    {
                        report.RegisterData(dt_Data28, dt_Data28Name);
                    }
                    #endregion

                    if (dt_Data2 != null)
                    {
                        if (dt_Data1 != null && dt_Data1.Rows.Count != 0)
                        {
                            string Path = "";
                            for (int i = 0; i < dt_Data1.Rows.Count; i++)
                            {
                                Path += dt_Data1.Rows[i][0];
                            }

                            //导出
                            if (ReportStatus.Equals("导出PDF"))
                            {
                                //Path += ".PDF";
                                //FastReport.EnvironmentSettings eSet = new FastReport.EnvironmentSettings();
                                //eSet.ReportSettings.ShowProgress = false;//解决弹出进度条,暂时注掉 by shx 220907
                                report.Prepare();
                                PDFExport export = new PDFExport();
                                #region 压缩的属性[已经是默认值的]
                                //export.Compressed = true;
                                //export.TextInCurves = false;//曲线文本
                                //export.ImagesOriginalResolution = false;//原始分辨率
                                //export.JpegCompression = false;//Jpeg压缩
                                //export.ColorSpace = PDFExport.PdfColorSpace.RGB;//色彩空间
                                #endregion
                                export.EmbeddingFonts = false;//嵌入字体
                                export.Background = false;//背景
                                export.PrintOptimized = false;//打印优化 ,压缩 by shx 20201221
                                export.EmbeddingFonts = true;//by shx 211229 解决导出的pdf在手机乱码
                                report.Export(export, Path);
                                report.Dispose();
                            }
                            else if (ReportStatus.Equals("导出Excel"))
                            {
                                Path += ".xlsx";
                                report.Prepare();
                                Excel2007Export xlsExport = new Excel2007Export();
                                report.Export(xlsExport, Path);
                                report.Dispose();
                            }
                        }
                    }

                    printReturn.Status = 1;
                    printReturn.PrintName = report.PrintSettings.Printer;//获取打印机名称report.PrintSettings.Printer
                    return printReturn;
                }
                #endregion
            }
            else
            {
                printReturn.Status = 0;
                printReturn.PrintName = "";
                return printReturn;//未找到报表
            }
        }
        #endregion


        //报表设计配置：一个体检编号需要打印常规体检报告，但是要选择自定义报表，这个时候需要在打开常规体检报告的设计页面之前把自定义报表的二进制数据赋值给常规体检报告
        #region 自定义报表设计方法   PS:暂时舍弃，因为数据对比问题，复制过去的报表文件在没有编辑的情况下是不等的，疑似复制为追加。
        ////参数dt_Data/当前模块数据源；dt_DataName/当前模块数据源名称；ReportCode/报表编码；NewReportCode/自定义报表编码；dt_Data1/预留数据源；dt_Data1Name/预留数据源名称
        public static void NewReportDesign(DataTable dt_Data, string dt_DataName, string ReportCode, string NewReportCode, DataTable dt_Data1 = null, string dt_Data1Name = null,
            DataTable dt_Data2 = null, string dt_Data2Name = null, DataTable dt_Data3 = null, string dt_Data3Name = null, DataTable dt_Data4 = null, string dt_Data4Name = null,
            DataTable dt_Data5 = null, string dt_Data5Name = null, DataTable dt_Data6 = null, string dt_Data6Name = null, DataTable dt_Data7 = null, string dt_Data7Name = null,
            DataTable dt_Data8 = null, string dt_Data8Name = null, DataTable dt_Data9 = null, string dt_Data9Name = null, DataTable dt_Data10 = null, string dt_Data10Name = null,
            DataTable dt_Data11 = null, string dt_Data11Name = null, DataTable dt_Data12 = null, string dt_Data12Name = null, DataTable dt_Data13 = null, string dt_Data13Name = null,
            DataTable dt_Data14 = null, string dt_Data14Name = null, DataTable dt_Data15 = null, string dt_Data15Name = null, DataTable dt_Data16 = null, string dt_Data16Name = null,
            DataTable dt_Data17 = null, string dt_Data17Name = null)
        {

            #region 根据报表编码查询报表数据；封装方法参数为Code/报表编码
            DataTable dt_page = null;//BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");
            if (dt_page.Rows.Count <= 0)
            {
                //创建预约单对应的报表新数据
                //ReportPageInfo pageinfo = new ReportPageInfo();
                //pageinfo.Code = ReportCode; //封装方法参数为Code / 报表编码
                //pageinfo.VersionNumber = 1;//版本默认1
                //pageinfo.SyncTag = true;//同步状态默认true，需要同步
                //pageinfo.Creator = loginUserInfo.FullName;
                //pageinfo.CreateTime = DateTime.Now;
                ////查找未分组报表类型(没有则创建)
                //ReportTypeInfo typeinfo = new ReportTypeInfo();
                //DataTable dt_Type = BLLFactory<ReportType>.Instance.SqlTable("select * from TB_RPT_Type where Name='未分组'");
                //if (dt_Type.Rows.Count <= 0)
                //{
                //    typeinfo.Code = "WFZ";
                //    typeinfo.Name = "未分组";
                //    typeinfo.Creator = loginUserInfo.FullName;
                //    typeinfo.CreateTime = DateTime.Now;
                //    BLLFactory<ReportType>.Instance.Insert(typeinfo);
                //}
                //DataTable dt_Type1 = BLLFactory<ReportType>.Instance.SqlTable("select * from TB_RPT_Type where Name='未分组' and Code = 'WFZ' ");
                //if (dt_Type1.Rows.Count > 0)
                //{
                //    pageinfo.TypeID = Convert.ToInt32(dt_Type1.Rows[0]["ID"]);
                //    BLLFactory<ReportPage>.Instance.Insert(pageinfo);
                //}
            }
            #endregion

            #region 报表设计功能前置逻辑
            //查询报表编码查询报表数据；封装方法参数为Code/报表编码
            DataTable TB_RPT_Page = null; //BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
            int PageID = Convert.ToInt32(TB_RPT_Page.Rows[0]["ID"]);
            string Code = Convert.ToString(TB_RPT_Page.Rows[0]["Code"]);//编码
            string VersionNumber = Convert.ToString(TB_RPT_Page.Rows[0]["VersionNumber"]);//版本
            if (string.IsNullOrEmpty(VersionNumber) || VersionNumber.Equals("0"))
            {
                VersionNumber = "1";
            }
            Byte[] FileStream = (Byte[])(TB_RPT_Page.Rows[0]["FileStream"]);
            string ReportName = Code + "_" + VersionNumber;
            bool SyncTag = Convert.ToBoolean(TB_RPT_Page.Rows[0]["SyncTag"]);//同步状态

            if (SyncTag)//需要同步
            {
                //校验是否需要创建文件夹
                if (!System.IO.Directory.Exists(@".//FastReports"))
                {
                    System.IO.Directory.CreateDirectory(@".//FastReports");
                }
                //判断选中数据FileStream报表二进制值是否为空(为空就调用本地空白标准模板并转换为二进制值)
                if (FileStream.Length <= 0)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //创建或打开指定文件并传入二进制值
                using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsOpen.Write(FileStream, 0, FileStream.Length);
                    fsOpen.Close();
                }
            }
            else//不需要同步
            {
                //获取标准模板
                if (FileStream.Length <= 0)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //查询报表编码查询报表数据；封装方法参数为Code/报表编码
                DataTable dtVersionNumber = null; //BLLFactory<ReportPageSVN>.Instance.SqlTable(@" select Code,VersionNumber from TB_RPT_Page_SVN where Code='" + ReportCode + @"'
                    //union
                    //select Code, VersionNumber from TB_RPT_Page where Code = '" + ReportCode + "' ");
                string fileReportName = "";
                if (dtVersionNumber.Rows.Count > 0)
                {
                    for (int i = dtVersionNumber.Rows.Count - 1; i >= 0; i--)
                    {
                        string code = Convert.ToString(dtVersionNumber.Rows[i]["Code"]);
                        string number = Convert.ToString(dtVersionNumber.Rows[i]["VersionNumber"]);
                        string Name = code + "_" + number;
                        if (File.Exists(@".//FastReports\" + Name + ".frx"))//文件已存在
                        {
                            //查询到指定数据，跳出循环
                            fileReportName = Name;
                            break;
                        }
                    }
                    //如果本地无对应文件则调用数据库二进制字段
                    if (string.IsNullOrEmpty(fileReportName))
                    {
                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                    else//如果本地有对应文件则把对应文件名赋值给报表文件名字段(此处赋值是因为后续打开报表设计页面固定调用ReportName变量。)
                    {
                        ReportName = fileReportName;
                    }
                }
            }
            #endregion

            #region 打开设计页面之前获取原始报表文件二进制数据，用于后续对比
            FileStream fsSave1 = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.Open);
            BinaryReader br1 = new BinaryReader(fsSave1);
            Byte[] OldFileStream = br1.ReadBytes((int)fsSave1.Length);//原始报表二进制数据，用于创建本地新文件
            fsSave1.Close();
            #endregion 

            #region 自定义报表数据复制给默认报告报表
            Byte[] CustomFileStream = new byte[0];
            if (!string.IsNullOrEmpty(NewReportCode))
            {
                CustomFileStream = GetCustomData(NewReportCode);
                //创建或打开指定文件并传入二进制值
                using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsOpen.Write(CustomFileStream, 0, CustomFileStream.Length);
                    fsOpen.Close();
                }
            }
            #endregion

            #region 打开设计页面编辑并保存
            //打开报表设计页面(方法需要预先手动创建对应FastReport空报表文件)
            FastReport.Report report = new FastReport.Report();
            report.Load(@".//FastReports\" + ReportName + ".frx");
            //加载数据源
            report.RegisterData(dt_Data, dt_DataName);

            #region 预留数据集位置
            if (dt_Data1 != null)
            {
                report.RegisterData(dt_Data1, dt_Data1Name);
            }
            if (dt_Data2 != null)
            {
                report.RegisterData(dt_Data2, dt_Data2Name);
            }
            if (dt_Data3 != null)
            {
                report.RegisterData(dt_Data3, dt_Data3Name);
            }
            if (dt_Data4 != null)
            {
                report.RegisterData(dt_Data4, dt_Data4Name);
            }
            if (dt_Data5 != null)
            {
                report.RegisterData(dt_Data5, dt_Data5Name);
            }
            if (dt_Data6 != null)
            {
                report.RegisterData(dt_Data6, dt_Data6Name);
            }
            if (dt_Data7 != null)
            {
                report.RegisterData(dt_Data7, dt_Data7Name);
            }
            if (dt_Data8 != null)
            {
                report.RegisterData(dt_Data8, dt_Data8Name);
            }
            if (dt_Data9 != null)
            {
                report.RegisterData(dt_Data9, dt_Data9Name);
            }
            if (dt_Data10 != null)
            {
                report.RegisterData(dt_Data10, dt_Data10Name);
            }
            if (dt_Data11 != null)
            {
                report.RegisterData(dt_Data11, dt_Data11Name);
            }
            if (dt_Data12 != null)
            {
                report.RegisterData(dt_Data12, dt_Data12Name);
            }
            if (dt_Data13 != null)
            {
                report.RegisterData(dt_Data13, dt_Data13Name);
            }
            if (dt_Data14 != null)
            {
                report.RegisterData(dt_Data14, dt_Data14Name);
            }
            if (dt_Data15 != null)
            {
                report.RegisterData(dt_Data15, dt_Data15Name);
            }
            if (dt_Data16 != null)
            {
                report.RegisterData(dt_Data16, dt_Data16Name);
            }
            if (dt_Data17 != null)
            {
                report.RegisterData(dt_Data17, dt_Data17Name);
            }
            #endregion

            report.Design();
            //报表设计操作完毕、报表文件转换为二进制数据
            FileStream fsSave = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.Open);
            BinaryReader br = new BinaryReader(fsSave);
            FileStream = br.ReadBytes((int)fsSave.Length);
            Byte[] NewFileStream = FileStream;//最新报表二进制数据，用于创建本地新文件
            fsSave.Close();
            //ReportPageInfo info = BLLFactory<ReportPage>.Instance.FindByID(PageID);

            #region 根据报表数据是否相同判断需不需要版本控制

            //创建一个哈希算法对象 
            using (HashAlgorithm hash = HashAlgorithm.Create())
            {
                byte[] hashByte1 = hash.ComputeHash(NewFileStream);//哈希算法根据文本得到哈希码的字节数组 
                byte[] hashByte2 = hash.ComputeHash(OldFileStream);
                string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串 
                string str2 = BitConverter.ToString(hashByte2);
                if (!str1.Equals(str2))
                {
                    ////保存原本数据到SVN版本备份表
                    //ReportPageSVNInfo SVNInfo = new ReportPageSVNInfo
                    //{
                    //    TypeID = info.TypeID,
                    //    Code = info.Code,
                    //    Name = info.Name,
                    //    FileStream = info.FileStream,
                    //    VersionNumber = info.VersionNumber,
                    //    Creator = loginUserInfo.FullName,
                    //    CreateTime = DateTime.Now
                    //};
                    //BLLFactory<ReportPageSVN>.Instance.Insert(SVNInfo);
                    ////更新正式表版本号并保存
                    //info.Modifier = loginUserInfo.FullName;
                    //info.ModiTime = DateTime.Now;
                    //info.ModifyNum = info.ModifyNum + 1;
                    //info.FileStream = FileStream;
                    //info.VersionNumber = info.VersionNumber + 1;
                    //try
                    //{
                    //    BLLFactory<ReportPage>.Instance.Update(info, info.ID);
                    //    FileStream = info.FileStream;
                    //}
                    //catch (Exception ex)
                    //{
                    //    LogTextHelper.Error(ex);
                    //    MessageDxUtil.ShowError(ex.Message);
                    //}
                }
            }
            #endregion

            #region 修改本地文件名
            if (!SyncTag)//不需要同步
            {
                //创建一个哈希算法对象 
                using (HashAlgorithm hash = HashAlgorithm.Create())
                {
                    byte[] hashByte1 = hash.ComputeHash(NewFileStream);//哈希算法根据文本得到哈希码的字节数组 
                    byte[] hashByte2 = hash.ComputeHash(OldFileStream);
                    string str1 = BitConverter.ToString(hashByte1);//将字节数组装换为字符串 
                    string str2 = BitConverter.ToString(hashByte2);
                    if (!str1.Equals(str2))
                    {
                        DataTable Page = null; //BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + ReportCode + "' ");//查询预约单报表数据
                        string NewCode = Convert.ToString(Page.Rows[0]["Code"]);//编码
                        string NewVersionNumber = Convert.ToString(Page.Rows[0]["VersionNumber"]);//版本
                        if (string.IsNullOrEmpty(NewVersionNumber) || NewVersionNumber.Equals("0"))
                        {
                            NewVersionNumber = "1";
                        }
                        string NewReportName = NewCode + "_" + NewVersionNumber;

                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + NewReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                }
            }
            #endregion

            #endregion
        }
        #endregion

        #region 获取自定义报表二进制数据
        public static Byte[] GetCustomData(string NewReportCode)
        {
            #region 报表设计功能前置逻辑
            //查询报表编码查询报表数据；封装方法参数为Code/报表编码
            DataTable TB_RPT_Page = null; //BLLFactory<ReportPage>.Instance.SqlTable(" select * from TB_RPT_Page where Code='" + NewReportCode + "' ");//查询预约单报表数据
            int PageID = Convert.ToInt32(TB_RPT_Page.Rows[0]["ID"]);
            string Code = Convert.ToString(TB_RPT_Page.Rows[0]["Code"]);//编码
            string VersionNumber = Convert.ToString(TB_RPT_Page.Rows[0]["VersionNumber"]);//版本
            if (string.IsNullOrEmpty(VersionNumber) || VersionNumber.Equals("0"))
            {
                VersionNumber = "1";
            }
            Byte[] FileStream = (Byte[])(TB_RPT_Page.Rows[0]["FileStream"]);
            string ReportName = Code + "_" + VersionNumber;
            bool SyncTag = Convert.ToBoolean(TB_RPT_Page.Rows[0]["SyncTag"]);//同步状态

            if (SyncTag)//需要同步
            {
                //校验是否需要创建文件夹
                if (!System.IO.Directory.Exists(@".//FastReports"))
                {
                    System.IO.Directory.CreateDirectory(@".//FastReports");
                }
                //判断选中数据FileStream报表二进制值是否为空(为空就调用本地空白标准模板并转换为二进制值)
                if (FileStream.Length <= 0)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //创建或打开指定文件并传入二进制值
                using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                {
                    fsOpen.Write(FileStream, 0, FileStream.Length);
                    fsOpen.Close();
                }
            }
            else//不需要同步
            {
                //获取标准模板
                if (FileStream.Length <= 0)
                {
                    FileStream fsAdd = new FileStream(@".//FastReports\StandardTemplate.frx", FileMode.Open);
                    BinaryReader brAdd = new BinaryReader(fsAdd);
                    FileStream = brAdd.ReadBytes((int)fsAdd.Length);
                    fsAdd.Close();
                }
                //查询报表编码查询报表数据；封装方法参数为Code/报表编码
                DataTable dtVersionNumber = null; //BLLFactory<ReportPageSVN>.Instance.SqlTable(@" select Code,VersionNumber from TB_RPT_Page_SVN where Code='" + NewReportCode + @"'
                     //union
                     //select Code, VersionNumber from TB_RPT_Page where Code = '" + NewReportCode + "' ");
                string fileReportName = "";
                if (dtVersionNumber.Rows.Count > 0)
                {
                    for (int i = dtVersionNumber.Rows.Count - 1; i >= 0; i--)
                    {
                        string code = Convert.ToString(dtVersionNumber.Rows[i]["Code"]);
                        string number = Convert.ToString(dtVersionNumber.Rows[i]["VersionNumber"]);
                        string Name = code + "_" + number;
                        if (File.Exists(@".//FastReports\" + Name + ".frx"))//文件已存在
                        {
                            //查询到指定数据，跳出循环
                            fileReportName = Name;
                            break;
                        }
                    }
                    //如果本地无对应文件则调用数据库二进制字段
                    if (string.IsNullOrEmpty(fileReportName))
                    {
                        //创建或打开指定文件并传入二进制值
                        using (FileStream fsOpen = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            fsOpen.Write(FileStream, 0, FileStream.Length);
                            fsOpen.Close();
                        }
                    }
                    else//如果本地有对应文件则把对应文件名赋值给报表文件名字段(此处赋值是因为后续打开报表设计页面固定调用ReportName变量。)
                    {
                        ReportName = fileReportName;
                    }
                }
            }
            #endregion

            //报表设计操作完毕、报表文件转换为二进制数据
            FileStream fsSave = new FileStream(@".//FastReports\" + ReportName + ".frx", FileMode.Open);
            BinaryReader br = new BinaryReader(fsSave);
            FileStream = br.ReadBytes((int)fsSave.Length);
            Byte[] NewFileStream = FileStream;//最新报表二进制数据，用于创建本地新文件
            fsSave.Close();
            return NewFileStream;
        }
        #endregion

    }
}